<template>
  <div class="new-course">
    <!-- 中间部分 -->
    <div class="new-course-main">
      <!-- 中间部分的头部 -->
      <div class="new-course-top">
        <!-- 标题图标 -->
        <div class="title-hot">
          <div class="hot">HOT</div>
          <div class="hot-c"></div>
        </div>
        <!-- 标题 -->
        <div class="title-text">新上好课</div>
      </div>
      <!-- 中间部分的下部分主体 -->
      <ul class="new-course-bottom">
        <li
          v-for="item in courseList"
          :key="item.id"
          @click="goDetail(item.id)"
          class="courseItem"
        >
          <img :src="item.courseCover" alt="" />
          <div class="course-content">
            <h3>{{ item.courseName }}</h3>
            <div class="div-one">
              {{ courseTypeFn(item.courseLevel) }} - {{ item.clicks }}人报名
            </div>
            <div class="div-two">
              <div class="div-vip">会员专享</div>
              <div class="div-price">￥{{ item.discountPrice }}</div>
            </div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup>
import { onBeforeMount } from "@vue/runtime-core";
//api
import { mostNew } from "../../utils/api/coures";

//mixins混入;
import courseType from "../../mixins/course.js";
let { courseTypeFn } = courseType();
// 新上好课的数据
let courseList = ref([]);
//生命周期
onBeforeMount(() => {
  mostNew({
    pageNum: 1,
    pageSize: 8,
  }).then((res) => {
    courseList.value = res.data.pageInfo.list;
    // console.log(res.data.pageInfo.list);
  });
});

let router = useRouter();
//进入课程详细页
const goDetail = (id) => {
  router.push({
    path: "/course/detail",
    query: {
      id,
    },
  });
};
</script>

<style lang="scss" scoped>
.new-course-main {
  width: 1000px;
  margin: 0 auto;
  .new-course-top {
    display: flex;
    margin-bottom: 20px;
    .title-hot {
      display: flex;
      .hot {
        width: 65px;
        height: 25px;
        background: linear-gradient(90deg, #ff727f 0%, #fc685c 100%);
        border-radius: 5px 0px 5px 5px;
        // align-items: center;
        color: white;
        text-align: center;
      }
      .hot-c {
        width: 0;
        height: 0;
        border: 3px solid #ff727f;
        border-bottom-color: transparent;
        border-right-color: transparent;
        // border-left: transparent;
        // border-r: transparent;
      }
    }
    .title-text {
      position: relative;
      margin-left: 5px;
      font-size: 23px;
      color: #333333;
      line-height: 24px;
      &::after {
        content: "";
        position: absolute;

        left: 0;
        bottom: 0;
        width: 103px;
        height: 9px;
        border-radius: 5px;
        z-index: -1;
        background: linear-gradient(90deg, #fbf84f 0%, #fea935 100%);
      }
    }
  }
  .courseItem {
    border-radius: 22px;
    margin-bottom: 20px;
    transition: margin-top 0.2s;
    & img {
      border-radius: 22px;
    }
  }
  .courseItem:hover {
    margin-top: -10px;
    cursor: pointer;
    border-radius: 22px;
  }
  a {
    position: relative;
    width: 100%;
    height: 270px;
    background: #ffffff;
    box-shadow: 1px 1px 10px rgb(27 39 94 / 40%);
    opacity: 1;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
    overflow: hidden;
    text-decoration: none;
  }
  .courseItem:nth-child(4n + 0) {
    margin-right: 0 !important;
  }
  .new-course-bottom {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap; //可换行
    & li {
      float: left;
      width: 240px;
      height: 275px;
      background: #ffffff;
      box-shadow: 1px 3px 3px rgba(27, 39, 94, 0.1);
      & img {
        width: 240px;
        height: 153px;
      }

      .course-content {
        padding: 14px 16px;

        & h3 {
          font-size: 12px;
          color: #333333;
        }
        .div-one {
          padding: 7px 0;
          font-size: 12px;
          color: #808080;
        }
        .div-two {
          display: flex;
          .div-vip {
            width: 64px;
            height: 16px;
            font-size: 12px;
            text-align: center;
            color: #fff;
            margin-right: 16px;
            background: linear-gradient(90deg, #ff928e 0%, #fe7062 99%);
            border-radius: 16px 0px 16px 0px;
          }
          .div-price {
            font-size: 12px;
            color: #ff727f;
          }
        }
      }
    }
  }
}
</style>
